################################################################################################### # Script to change the value of an enumeration attribute for all objects which have this attribute ################################################################################################### CC "Modeling" GET_ACT_MODEL SET n_modelId:(modelid) IF (n_modelId = -1) { CC "AdoScript" ERRORBOX "Error: No model currently open" EXIT } # First we retrieve all objects in the active model, and put the object ids in a list "l_objIds" CC "Core" GET_ALL_OBJS modelid:(n_modelId) SET l_objIds:(objids) # The attribute name whose value we wish to change is called "Colour" here, and is of type enumeration # For all objects with the attribute Colour, we wish to change the current value to some new value # We allow user interaction, to select what the new value should be SET n_valFound:1 # Loop over all objects in the current model FOR s_objId in:(l_objIds) { CC "Core" GET_CLASS_ID objid:(VAL s_objId) SET n_classId:(classid) CC "Core" GET_ATTR_ID classid:(n_classId) attrname:("Colour") SET n_attributeId:(attrid) # Check whether the current object has an attribute called "Colour" # If the current object does not have this attribute, GET_ATTR_ID returns "-1" and nothing is done, # otherwise the following IF{..} block is executed IF (attrid != -1) { # This IF {..} block presents a selection tool to select the value desired, we only do this once (using the value of n_valFound) IF (n_valFound=1) { # Read the enumeration domain (i.e. the list of options for the enumeration attribute) CC "Core" GET_FACET_ENUMERATIONDOMAIN attrid:(n_attributeId) SET s_enumerationDomain:(val) CC "Core" GET_ATTR_VAL objid:(VAL s_objId) attrname:"Colour" SET s_currentSelection:(val) # Present selection box, to set the desired value (which is then stored in s_enumVal) CC "AdoScript" LISTBOX entries: (s_enumerationDomain) toksep:"@" title:"Select attribute value" oktext:"Apply" boxtext:"Attribute value:" selection:(s_currentSelection) IF (endbutton = "ok") { SET s_enumVal:(selection) } } SET n_valFound:(n_valFound + 1) # Now we set the selected value for the current object in our loop over all objects CC "Core" SET_ATTR_VAL objid:(VAL s_objId) attrname:"Colour" val:(s_enumVal) } }